//
//  NSString+Extensions.swift
//  SwiftDemo
//
//  Created by Chris on 2017/6/14.
//  Copyright © 2017年 chris. All rights reserved.
//

import Foundation

extension NSString {
    
    /// 给当前文件追加document路径
    ///
    /// - Returns: 路径
    func appendingDocumentDirectory() -> NSString {
        let dir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! as NSString
        
        return dir.appendingPathComponent(self.lastPathComponent) as NSString
    }
    
    /// 给当前文件追加cache路径
    ///
    /// - Returns: 路径
    func appendingCacheDirectory() -> NSString {
        let dir = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first! as NSString
        
        return dir.appendingPathComponent(self.lastPathComponent) as NSString
    }
    
    /// 给当前文件追加temp路径
    ///
    /// - Returns: 路径
    func appendingTempDirectory() -> NSString {
        let dir = NSTemporaryDirectory() as NSString
        
        return dir.appendingPathComponent(self.lastPathComponent) as NSString
    }
}
